package com.demonzym;

import java.io.File;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.demonzym.framework.activitymanager.ActivityBase;
import com.demonzym.framework.image.ImageManager;
import com.demonzym.framework.image.ImageManager.IImageDownloadListener;
import com.demonzym.framework.media.MediaManager;
import com.demonzym.framework.net.http.HttpListener.IHttpListener;
import com.demonzym.framework.net.http.HttpManager;
import com.demonzym.framework.net.http.HttpRequest;
import com.demonzym.framework.net.http.HttpResponse;
import com.demonzym.framework.net.http.MyHttp;
import com.demonzym.framework.sdcard.SdCard;
import com.demonzym.framework.widget.HorizontalListView;

public class MyAndroidFrameWorkActivity extends ActivityBase implements OnKeyListener{
	
	TextView tv;
	ProgressBar pg;
	ImageView image;
	int httpid;
	
//	AutoSwitchImageActivity asvp;

	Uri uri;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		
		Log.e("", "create");

		ini();
		
//		String path = SdCard.getSDRoot() + "/demonzym/";
//		File file = new File(path);
//		uri = Uri.fromFile(file);
//		MediaManager.capturePhoto(this, uri, 1);
//		MediaManager.selectPicture(this);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		
		if(requestCode == MediaManager.REQUEST_CODE_SELECT_PIC)
			image.setImageURI(MediaManager.onPictureSelect(data));

		if(requestCode == MediaManager.REQUEST_CODE_CAPTURE_PHOTO)
			image.setImageBitmap(MediaManager.onCapturePhoto(this, data, uri));
	}

	private void ini() {
		tv = (TextView) findViewById(R.id.maintext);
		pg = (ProgressBar) findViewById(R.id.progressBar1);
		image = (ImageView) findViewById(R.id.imageView1);
		
		HorizontalListView lv = (HorizontalListView) findViewById(R.id.horizontalListView1);
		String[] dataObjects = new String[]{ "Text #1",
			"Text #2",
			"Text #3" ,
			"Text #2",
			"Text #3" ,
			"Text #2",
			"Text #3" ,
			"Text #2",
			"Text #3" ,
			"Text #2",
			"Text #3" ,
			"Text #2",
			"Text #3" }; 
		ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataObjects);
		lv.setAdapter(aa);
		
//		HttpManager.pushHttp(new HttpRequest("www.360.cn").setENCODE("gbk"), new IHttpListener() {
//			
//			@Override
//			public void onSuccess(int requestId, String data, HttpResponse hr) {
//				Toast.makeText(MyAndroidFrameWorkActivity.this, data, Toast.LENGTH_SHORT).show();
//			}
//			
//			@Override
//			public void onError(int requestId, int errorCode, String error, HttpResponse hr) {
//				tv.setText("cuowu");
//			}
//		});
//		ImageManager.getInstance().getImage("http://126.fm/2VfNYg",
//				new IImageDownloadListener() {
//			
//			@Override
//			public void onGetImageError() {
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void onGetImage(Bitmap bitmap, String localPath) {
//				image.setImageBitmap(bitmap);
//			}
//			
//			@Override
//			public void onDownloading(int cur, int max) {
//				tv.setText(cur + "/" + max);
//				pg.setMax(max);
//				pg.setProgress(cur);
//			}
//		});
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
			finish();
		return false;
	}
	
}